package com.patrol.patrol.ui.appear;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.patrol.patrol.MyApplication;
import com.patrol.patrol.R;
import com.patrol.patrol.data.EventModel;
import com.patrol.patrol.ui.BaseFragment;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class ListFragment extends BaseFragment {

    Unbinder unbinder;
    ListAdapter equipListAdapter;
    @BindView(R.id.rcy_equip)
    RecyclerView rcyEquip;

    @Override
    protected void onCreateView(Bundle savedInstanceState) {
        super.onCreateView(savedInstanceState);
        setContentView(R.layout.fragment_list);
        unbinder = ButterKnife.bind(this, getContentView());

        rcyEquip.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL,false));

        List<EventModel> modelList = MyApplication.dbProxy.queryListBySql(EventModel.class,"select * from event_model");
        equipListAdapter = new ListAdapter(getContext(),modelList);
        rcyEquip.setAdapter(equipListAdapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onResume() {
        super.onResume();
        List<EventModel> modelList = MyApplication.dbProxy.queryListBySql(EventModel.class,"select * from event_model");
        equipListAdapter.modelList.clear();
        equipListAdapter.modelList.addAll(modelList);
        equipListAdapter.notifyDataSetChanged();
    }
}
